package org.example;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.observables.GroupedObservable;

public class Demo1 {
    public static void main(String[] args) {
        Observable.range(0,10)
                .groupBy(new Function<Integer, Integer>() {
                    @Override
                    public Integer apply(@NonNull Integer integer) throws Exception {
                        return integer / 3;
                    }
                })
                .subscribe(new Consumer<GroupedObservable<Integer, Integer>>() {
                    @Override
                    public void accept(GroupedObservable<Integer, Integer> groupedObservable) throws Exception {
                        int key = groupedObservable.getKey();
                        System.err.println("key=" + key);
                        groupedObservable.subscribe(new Consumer<Integer>() {
                            @Override
                            public void accept(Integer integer) throws Exception {
                                System.err.println("integer=" + integer);
                            }
                        });
                    }
                });
    }
}
